package cuongnh.project.japanesediary.vocabulary.ui.wizard.page;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import cuongnh.project.japanesediary.vocabulary.model.Kanji;

public class NewKanjiWizardPage extends WizardPage {
	private DataBindingContext m_bindingContext;
	private final FormToolkit toolkit = new FormToolkit(Display.getDefault());
	private Text txtKanji;
	private Text txtOnyomi;
	private Text txtKunyomi;
	private Text txtHanviet;
	private Text txtStrokes;
	private Text txtGrade;
	private Text txtFrequency;
	private Kanji kanji;
	private StyledText txtVnMeaning;
	private StyledText txtEnMeaning;
	private StyledText txtJpMeaning;
	private StyledText txtVnExplaination;
	private StyledText txtEnExplaination;
	private StyledText txtJpExplaination;

	/**
	 * Create the wizard.
	 */
	public NewKanjiWizardPage(Kanji kanji) {
		super("wizardPage");
		setTitle("Wizard Page title");
		setDescription("Wizard Page description");
		this.kanji = kanji;
	}

	/**
	 * Create contents of the wizard.
	 * 
	 * @param parent
	 */
	public void createControl(Composite parent) {
		parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		Composite container = new Composite(parent, SWT.NULL);
		container.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));

		setControl(container);
		container.setLayout(new GridLayout(2, false));

		Group grpKanji = new Group(container, SWT.NONE);
		grpKanji.setLayout(new GridLayout(4, false));
		GridData gd_grpKanji = new GridData(SWT.FILL, SWT.FILL, false, false,
				1, 1);
		gd_grpKanji.heightHint = 211;
		gd_grpKanji.widthHint = 262;
		grpKanji.setLayoutData(gd_grpKanji);
		grpKanji.setText("Kanji");
		toolkit.adapt(grpKanji);
		toolkit.paintBordersFor(grpKanji);

		txtKanji = new Text(grpKanji, SWT.BORDER | SWT.CENTER);
		txtKanji.setText("\u52C9");
		txtKanji.setBackground(SWTResourceManager.getColor(240, 230, 140));
		txtKanji.setForeground(SWTResourceManager.getColor(0, 0, 0));
		txtKanji.setFont(SWTResourceManager
				.getFont("MS Gothic", 32, SWT.NORMAL));
		txtKanji.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				4, 1));

		Label lblNewLabel = new Label(grpKanji, SWT.SHADOW_NONE);
		lblNewLabel
				.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
		lblNewLabel.setFont(SWTResourceManager
				.getFont("Segoe UI", 10, SWT.BOLD));
		lblNewLabel.setAlignment(SWT.CENTER);
		lblNewLabel.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		{
			GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.FILL, false,
					false, 1, 1);
			gd_lblNewLabel.widthHint = 73;
			lblNewLabel.setLayoutData(gd_lblNewLabel);
		}
		lblNewLabel.setText("Onyomi");

		txtOnyomi = new Text(grpKanji, SWT.BORDER);
		txtOnyomi.setBackground(SWTResourceManager.getColor(245, 222, 179));
		txtOnyomi.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				3, 1));

		Label lblKunyomi = new Label(grpKanji, SWT.NONE);
		lblKunyomi.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
		lblKunyomi.setAlignment(SWT.CENTER);
		lblKunyomi
				.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		lblKunyomi.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		lblKunyomi.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
				1, 1));
		lblKunyomi.setText("Kunyomi");

		txtKunyomi = new Text(grpKanji, SWT.BORDER);
		txtKunyomi.setBackground(SWTResourceManager.getColor(245, 222, 179));
		txtKunyomi.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 3, 1));

		Label lblHanviet = new Label(grpKanji, SWT.NONE);
		lblHanviet.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
		lblHanviet.setAlignment(SWT.CENTER);
		lblHanviet
				.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		lblHanviet.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		lblHanviet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
				1, 1));
		lblHanviet.setText("HAN-VIET");

		txtHanviet = new Text(grpKanji, SWT.BORDER);
		txtHanviet.setBackground(SWTResourceManager.getColor(245, 222, 179));
		txtHanviet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 3, 1));

		Label lblStrokes = new Label(grpKanji, SWT.SHADOW_NONE);
		lblStrokes.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
		lblStrokes
				.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		lblStrokes.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		lblStrokes.setAlignment(SWT.CENTER);
		GridData gd_lblStrokes = new GridData(SWT.FILL, SWT.FILL, false, false,
				2, 1);
		gd_lblStrokes.widthHint = 104;
		lblStrokes.setLayoutData(gd_lblStrokes);
		lblStrokes.setText("Strokes");

		txtStrokes = new Text(grpKanji, SWT.BORDER | SWT.CENTER);
		txtStrokes.setBackground(SWTResourceManager.getColor(245, 222, 179));
		GridData gd_txtStrokes = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1);
		gd_txtStrokes.widthHint = 122;
		txtStrokes.setLayoutData(gd_txtStrokes);

		Label lblGrade = new Label(grpKanji, SWT.NONE);
		lblGrade.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
		lblGrade.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		lblGrade.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		lblGrade.setAlignment(SWT.CENTER);
		lblGrade.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
				2, 1));
		lblGrade.setText("Grade");

		Label lblFrequency = new Label(grpKanji, SWT.NONE);
		lblFrequency.setForeground(SWTResourceManager
				.getColor(SWT.COLOR_YELLOW));
		lblFrequency.setFont(SWTResourceManager.getFont("Segoe UI", 10,
				SWT.BOLD));
		lblFrequency.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		lblFrequency.setAlignment(SWT.CENTER);
		{
			GridData gd_lblFrequency = new GridData(SWT.FILL, SWT.FILL, false,
					false, 2, 1);
			gd_lblFrequency.widthHint = 91;
			lblFrequency.setLayoutData(gd_lblFrequency);
		}
		lblFrequency.setText("Frequency");

		txtGrade = new Text(grpKanji, SWT.BORDER | SWT.CENTER);
		txtGrade.setBackground(SWTResourceManager.getColor(245, 222, 179));
		txtGrade.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				2, 1));

		txtFrequency = new Text(grpKanji, SWT.BORDER | SWT.CENTER);
		txtFrequency.setBackground(SWTResourceManager.getColor(245, 222, 179));
		txtFrequency.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1));

		Composite composite_1 = new Composite(container, SWT.NONE);
		composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_1.setLayout(new GridLayout(1, false));
		GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, true, false,
				1, 1);
		gd_composite_1.heightHint = 201;
		composite_1.setLayoutData(gd_composite_1);
		toolkit.paintBordersFor(composite_1);

		Group grpMeaning = new Group(composite_1, SWT.NONE);
		GridData gd_grpMeaning = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_grpMeaning.heightHint = 198;
		grpMeaning.setLayoutData(gd_grpMeaning);
		grpMeaning.setLayout(new GridLayout(1, false));
		grpMeaning.setText("Meaning");
		toolkit.adapt(grpMeaning);
		toolkit.paintBordersFor(grpMeaning);

		TabFolder tabFolder = new TabFolder(grpMeaning, SWT.NONE);
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));
		toolkit.adapt(tabFolder);
		toolkit.paintBordersFor(tabFolder);

		TabItem tbtmVietnamese = new TabItem(tabFolder, SWT.NONE);
		tbtmVietnamese.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/vietnam.jpg"));
		tbtmVietnamese.setText("Vietnamese");

		txtVnMeaning = new StyledText(tabFolder, SWT.BORDER);
		tbtmVietnamese.setControl(txtVnMeaning);
		toolkit.paintBordersFor(txtVnMeaning);

		TabItem tbtmEnglish = new TabItem(tabFolder, SWT.NONE);
		tbtmEnglish.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/england.jpg"));
		tbtmEnglish.setText("English");

		txtEnMeaning = new StyledText(tabFolder, SWT.BORDER);
		tbtmEnglish.setControl(txtEnMeaning);
		toolkit.paintBordersFor(txtEnMeaning);

		TabItem tbtmJapanese = new TabItem(tabFolder, SWT.NONE);
		tbtmJapanese.setImage(ResourceManager.getPluginImage(
				"cuongnh.project.japanesediary.vocabulary", "icons/japan.jpg"));
		tbtmJapanese.setText("Japanese");

		txtJpMeaning = new StyledText(tabFolder, SWT.BORDER);
		tbtmJapanese.setControl(txtJpMeaning);
		toolkit.paintBordersFor(txtJpMeaning);

		Group grpExplaination = new Group(container, SWT.NONE);
		grpExplaination.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
		grpExplaination.setLayout(new GridLayout(1, false));
		grpExplaination.setText("Explaination");
		toolkit.adapt(grpExplaination);
		toolkit.paintBordersFor(grpExplaination);

		TabFolder tabFolder_1 = new TabFolder(grpExplaination, SWT.NONE);
		GridData gd_tabFolder_1 = new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1);
		gd_tabFolder_1.heightHint = 280;
		tabFolder_1.setLayoutData(gd_tabFolder_1);
		toolkit.adapt(tabFolder_1);
		toolkit.paintBordersFor(tabFolder_1);

		TabItem tbtmVietnamese_1 = new TabItem(tabFolder_1, SWT.NONE);
		tbtmVietnamese_1.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/vietnam.jpg"));
		tbtmVietnamese_1.setText("Vietnamese");

		txtVnExplaination = new StyledText(tabFolder_1, SWT.BORDER);
		tbtmVietnamese_1.setControl(txtVnExplaination);
		toolkit.paintBordersFor(txtVnExplaination);

		TabItem tbtmEnglish_1 = new TabItem(tabFolder_1, SWT.NONE);
		tbtmEnglish_1.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/england.jpg"));
		tbtmEnglish_1.setText("English");

		txtEnExplaination = new StyledText(tabFolder_1, SWT.BORDER);
		tbtmEnglish_1.setControl(txtEnExplaination);
		toolkit.paintBordersFor(txtEnExplaination);

		TabItem tbtmJapanese_1 = new TabItem(tabFolder_1, SWT.NONE);
		tbtmJapanese_1.setImage(ResourceManager.getPluginImage(
				"cuongnh.project.japanesediary.vocabulary", "icons/japan.jpg"));
		tbtmJapanese_1.setText("Japanese");

		txtJpExplaination = new StyledText(tabFolder_1, SWT.BORDER);
		tbtmJapanese_1.setControl(txtJpExplaination);
		toolkit.paintBordersFor(txtJpExplaination);
		m_bindingContext = initDataBindings();
	}

	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTxtKanjiObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtKanji);
		IObservableValue kanjiKanjiObserveValue = BeanProperties.value("kanji")
				.observe(kanji);
		bindingContext.bindValue(observeTextTxtKanjiObserveWidget,
				kanjiKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtOnyomiObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtOnyomi);
		IObservableValue onyomiKanjiObserveValue = BeanProperties.value(
				"onyomi").observe(kanji);
		bindingContext.bindValue(observeTextTxtOnyomiObserveWidget,
				onyomiKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtKunyomiObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtKunyomi);
		IObservableValue kunyomiKanjiObserveValue = BeanProperties.value(
				"kunyomi").observe(kanji);
		bindingContext.bindValue(observeTextTxtKunyomiObserveWidget,
				kunyomiKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtKanetsuonObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtHanviet);
		IObservableValue kanetsuonKanjiObserveValue = BeanProperties.value(
				"hanviet").observe(kanji);
		bindingContext.bindValue(observeTextTxtKanetsuonObserveWidget,
				kanetsuonKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtStrokesObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtStrokes);
		IObservableValue strokesKanjiObserveValue = BeanProperties.value(
				"strokes").observe(kanji);
		bindingContext.bindValue(observeTextTxtStrokesObserveWidget,
				strokesKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtGradeObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtGrade);
		IObservableValue gradeKanjiObserveValue = BeanProperties.value("grade")
				.observe(kanji);
		bindingContext.bindValue(observeTextTxtGradeObserveWidget,
				gradeKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtFrequencyObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtFrequency);
		IObservableValue frequencyKanjiObserveValue = BeanProperties.value(
				"frequency").observe(kanji);
		bindingContext.bindValue(observeTextTxtFrequencyObserveWidget,
				frequencyKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtVnMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtVnMeaning);
		IObservableValue vnMeaningKanjiObserveValue = BeanProperties.value(
				"vnMeaning").observe(kanji);
		bindingContext.bindValue(observeTextTxtVnMeaningObserveWidget,
				vnMeaningKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtEnMeaning);
		IObservableValue enMeaningKanjiObserveValue = BeanProperties.value(
				"enMeaning").observe(kanji);
		bindingContext.bindValue(observeTextTxtEnMeaningObserveWidget,
				enMeaningKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtJpMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtJpMeaning);
		IObservableValue jpMeaningKanjiObserveValue = BeanProperties.value(
				"jpMeaning").observe(kanji);
		bindingContext.bindValue(observeTextTxtJpMeaningObserveWidget,
				jpMeaningKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtVnExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtVnExplaination);
		IObservableValue vnExplainationKanjiObserveValue = BeanProperties
				.value("vnExplaination").observe(kanji);
		bindingContext.bindValue(observeTextTxtVnExplainationObserveWidget,
				vnExplainationKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtEnExplaination);
		IObservableValue enExplainationKanjiObserveValue = BeanProperties
				.value("enExplaination").observe(kanji);
		bindingContext.bindValue(observeTextTxtEnExplainationObserveWidget,
				enExplainationKanjiObserveValue, null, null);
		//
		IObservableValue observeTextTxtJpExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtJpExplaination);
		IObservableValue jpExplainationKanjiObserveValue = BeanProperties
				.value("jpExplaination").observe(kanji);
		bindingContext.bindValue(observeTextTxtJpExplainationObserveWidget,
				jpExplainationKanjiObserveValue, null, null);
		//
		return bindingContext;
	}
}
